// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

import gameData from "../gameData";
import mainManage from "../../framework/mainManage";

const {ccclass, property} = cc._decorator;

let open = true;

@ccclass
export default class compensationMediator extends cc.Component {

    callback = null;

    showSkin = false;

    onLoad(){
        if(this.showSkin){
            this.node.getChildByName("part1").active = false;   
            this.node.getChildByName("part2").active = true;
        }else{
            this.node.getChildByName("part1").active = true;
            this.node.getChildByName("part2").active = false;
        }
    }

    btnClick(event,data){
        if(parseInt(data) == 1){
            gameData.colorfulPiece[0][6] = 1;
            gameData.saveColorfulPiece();
            mainManage.createToast("领取成功");
            this.node.destroy()
        }

        if(parseInt(data) == 2){
            this.node.destroy();
        }

        if(parseInt(data) == 3){
            gameData.savePetSkin(gameData.getPetProcessSkin().length - 1);
            mainManage.createToast("领取成功");
            this.node.destroy();
            if(this.callback != null){
                this.callback();
            }
        }
    }

    setCallBack(showSkin,callback){
        this.showSkin = showSkin;
        this.callback = callback;
    }
}
